﻿layui.use(['form', 'layer', 'table', 'laytpl', 'laydate'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laytpl = layui.laytpl,
        table = layui.table,
        laydate = layui.laydate;


    function loadDate() {
        laydate.render({
            elem: '#startdate'
        });
        laydate.render({
            elem: '#enddate'
        });
    }

    var tableIns = table.render({
        elem: '#managerList',
        url: '/HistoryCash/LoadData/',
        parseData: function (res) { //res 即为原始返回的数据
            var totalData = res.totalData
            $("#txtTotalInAmount").html('$'+totalData.TotalInAmount);
            $("#txtTotalInRMBAmount").html('$'+totalData.TotalInRMBAmount);
            $("#txtTotalOutAmount").html('$'+totalData.TotalOutAmount);
            $("#txtTotalOutRMBAmount").html('$'+totalData.TotalOutRMBAmount);
            return res;
        },
        cellMinWidth: 95,
        page: true,
        limits: [10, 15, 20, 25],
        limit: 10,
        id: "managerListTable",
        cols: [[
            { type: "checkbox", fixed: "left", width: 50 },
            { field: "Id", title: '序号', width: 70, align: "center" },
            { field: 'UserName', title: '交易号(姓名)', minWidth: 50, align: "center", templet: '#UserName' },
            { field: 'Amount', title: '金额(美元)', minWidth: 50, align: "center",  templet: '#Amount' },
            { field: 'Cash_State', title: '状态', minWidth: 80, align: "center", templet: '#State' },
            { field: 'Action_Time', title: '交易时间', minWidth: 80, align: "center" },
            { field: 'Remark', title: '备注', minWidth: 80, align: "center" }
        ]],
        totalRow: false  //开启合计行
    });

    //搜索【此功能需要后台配合，所以暂时没有动态效果演示】
    $(".search_btn").on("click", function () {
        
        table.reload("managerListTable", {
            page: {
                curr: 1 //重新从第 1 页开始
            },
            where: {
                key: $(".searchVal").val(),  //搜索的关键字
                state: $(".searchState").val(),
                start: $(".startdate").val(),
                end: $(".enddate").val(),
                ManagerId: $(".searchUserList").val()
            }
        });
        //} else {
        //    layer.msg("请输入搜索的内容");
        //}
    });

    loadDate();

});